package com.winteam.View;

import com.winteam.Bean.Admin;
import com.winteam.Bean.ClientPlus;
import com.winteam.Bean.RoomInfo;
import com.winteam.Bean.Statement;
import com.winteam.Controler.Select;
import com.winteam.Controler.Updata;
import org.junit.Test;

import javax.swing.*;
import javax.swing.table.DefaultTableCellRenderer;
import javax.swing.table.DefaultTableModel;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.Date;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Vector;

public class MainJFrame extends JFrame {
    /**
     * 登录之后的用户
     */
    Admin admin;
    /**
     * 左边的信息表
     */
    JLabel bkxm, ysdj, fjdh, fjlx, jdsj, yjyj;
    //设置布局管理器
    GridLayout gl = new GridLayout();
    BorderLayout bl = new BorderLayout();
    FlowLayout fl = new FlowLayout();
    Select select = new Select();
    Updata updata = new Updata();
    int v = ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED;//水平滚动条
    int h = ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED;//垂直滚动条

    Vector<Object> data;//结算信息二维数组
    JTabbedPane tabbedPane;//选项卡面板
    JLabel fjgg, Label_1, Label_2, Label_3, Label_4, Label_5, Label_6, Label_7, Label_8;//房间规格、详细信息
    String setroomtype = "1";//判断房间号


    //最近消费记录
    JTable StatementTable;
    DefaultTableModel StatementModel;

    public MainJFrame(Admin n) {
        super("酒店管理系统");
        admin = n;
        this.setSize(1600, 900);
        this.setLocationRelativeTo(null);//让窗口在中间
        this.setResizable(false);//让用户改变不了窗口大小
        getContentPane().setLayout(null);
        this.getContentPane().setBackground(Color.decode("#E7D7B7"));//设置背景颜色

        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);//用户单击窗口的关闭按钮时程序执行的操作

        //1.创建菜单工具栏
        JMenuBar jmb = new JMenuBar();
        jmb.setBackground(Color.decode("#E7D7B7"));
        //2.创建一级菜单JMenu
        JMenu guestRegistration = new JMenu("来宾登记(B)");
        guestRegistration.setMnemonic('B');//设置快捷方式
        //3.创建【来宾登记】的二级菜单
        JMenuItem B_individual_item = new JMenuItem("散客开单(G)");
        B_individual_item.setMnemonic('G');
        guestRegistration.add(B_individual_item);//4、将菜单项加入文件菜单条中
        B_individual_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                BillingInformationView billingInformationView = new BillingInformationView();
                billingInformationView.setVisible(true);
            }
        });

        JMenuItem B_group_item = new JMenuItem("团体开单(M)");
        B_group_item.setMnemonic('M');
        guestRegistration.add(B_group_item);
        B_group_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                TeamBilling teamBilling = new TeamBilling();
                teamBilling.setVisible(true);
            }
        });

        JMenuItem B_renew_item = new JMenuItem("宾客续住(Z)");
        B_renew_item.setMnemonic('Z');
        guestRegistration.add(B_renew_item);
        B_renew_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem B_change_item = new JMenuItem("更换房间(A)");
        B_change_item.setMnemonic('A');
        guestRegistration.add(B_change_item);
        B_change_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem B_alter_item = new JMenuItem("修改登记(J)");
        B_alter_item.setMnemonic('J');
        guestRegistration.add(B_alter_item);
        B_alter_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem B_state_item = new JMenuItem("房间状态(Z)");
        B_state_item.setMnemonic('Z');
        guestRegistration.add(B_state_item);
        B_state_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem B_reserve_item = new JMenuItem("预订管理(T)");
        B_reserve_item.setMnemonic('T');
        guestRegistration.add(B_reserve_item);
        B_reserve_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem B_remind_item = new JMenuItem("重新登录(L)");
        B_remind_item.setMnemonic('L');

        guestRegistration.add(B_remind_item);
        B_remind_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int result = JOptionPane.showConfirmDialog(null, "您确定要退出登录?", "退出提示", 0, 1);
                if (result == JOptionPane.OK_OPTION) {
                    Login login = new Login();
                    dispose();
                    login.setVisible(true);
                    ;
                }

            }
        });

        JMenuItem B_exit_item = new JMenuItem("退出系统(X)");
        B_exit_item.setMnemonic('X');
        guestRegistration.add(B_exit_item);
        jmb.add(guestRegistration);//5、将菜单栏加入文件菜单条中
        B_exit_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int result = JOptionPane.showConfirmDialog(null, "您现在要关闭系统吗?", "退出提示", 0, 1);
                if (result == JOptionPane.OK_OPTION) {
                    JOptionPane.showMessageDialog(null, "已退出系统，欢迎下次使用！");
                    System.exit(0);
                }
            }
        });


        JMenu editor = new JMenu("收银结算(S)");
        editor.setMnemonic('S');

        JMenuItem S_checkOut_item = new JMenuItem("宾客结账(J)");
        S_checkOut_item.setMnemonic('J');
        editor.add(S_checkOut_item);
        S_checkOut_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem S_Merg_item = new JMenuItem("合并账单(E)");
        S_Merg_item.setMnemonic('E');
        editor.add(S_Merg_item);
        S_Merg_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem S_split_item = new JMenuItem("拆分账单(F)");
        S_split_item.setMnemonic('F');
        editor.add(S_split_item);
        jmb.add(editor);//5、将菜单栏加入文件菜单条中
        S_split_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenu maintain = new JMenu("系统维护(W)");
        maintain.setMnemonic('W');
        JMenuItem W_networkSet_item = new JMenuItem("网络设置(N)");
        W_networkSet_item.setMnemonic('N');
        maintain.add(W_networkSet_item);
        W_networkSet_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem W_sysSet_item = new JMenuItem("系统设置(X)");
        W_sysSet_item.setMnemonic('X');
        maintain.add(W_sysSet_item);
        W_sysSet_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem W_sysLog_item = new JMenuItem("系统日志(Z)");
        W_sysLog_item.setMnemonic('Z');
        maintain.add(W_sysLog_item);
        W_sysLog_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem W_dataBackup_item = new JMenuItem("数据备份(R)");
        W_dataBackup_item.setMnemonic('R');
        maintain.add(W_dataBackup_item);
        W_dataBackup_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem W_help_item = new JMenuItem("软件帮助(H)");
        W_help_item.setMnemonic('H');
        maintain.add(W_help_item);
        W_help_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        JMenuItem W_about_item = new JMenuItem("关于我们(A)");
        W_about_item.setMnemonic('A');
        maintain.add(W_about_item);
        jmb.add(maintain);//5、将菜单栏加入文件菜单条中
        W_about_item.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                JOptionPane.showMessageDialog(null, "此功能暂未开放！");
            }
        });

        //6.将菜单工具栏加入JFrame中
        this.setJMenuBar(jmb);


        //创建图片ImageIcon对象
        ImageIcon icon1 = new ImageIcon(this.getClass().getResource("img/ToolBar/m01.gif"));
        icon1.setImage(icon1.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton skkd = new JButton("散客开单", icon1);

        skkd.setBounds(10, 10, 90, 100);
        skkd.setContentAreaFilled(false);//设置按钮透明背景
        skkd.setFocusPainted(false);//去掉按钮周围的焦点框
//		sk.setBorderPainted(false);//去边框
        skkd.setHorizontalTextPosition(SwingConstants.CENTER);
        skkd.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(skkd);
        skkd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                BillingInformationView billingInformationView = new BillingInformationView();

            }
        });
        ImageIcon icon2 = new ImageIcon(this.getClass().getResource("img/ToolBar/m02.gif"));
        icon2.setImage(icon2.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton ttkd = new JButton("团体开单", icon2);
        ttkd.setBounds(115, 10, 90, 100);
        ttkd.setContentAreaFilled(false);
        ttkd.setFocusPainted(false);
        ttkd.setHorizontalTextPosition(SwingConstants.CENTER);
        ttkd.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(ttkd);
        ttkd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                TeamBilling teamBilling = new TeamBilling();
                teamBilling.setVisible(true);
            }
        });
        ImageIcon icon3 = new ImageIcon(this.getClass().getResource("img/ToolBar/m04.gif"));
        icon3.setImage(icon3.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton bkjz = new JButton("宾客结账", icon3);
        bkjz.setBounds(220, 10, 90, 100);
        bkjz.setContentAreaFilled(false);
        bkjz.setFocusPainted(false);
        bkjz.setHorizontalTextPosition(SwingConstants.CENTER);
        bkjz.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(bkjz);
        bkjz.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
//                if (setroomtype=="1") {
//                    JOptionPane.showMessageDialog(null, "请选择要结算的房间！");
//                } else {
//                    String rjzt = select.getString("SELECT r_state.state FROM r_state,roominfo WHERE roominfo.state=number AND roomid='"+setroomtype+"'");
//                    if (rjzt.equals("使用中")) {
//                        Checkout_info che = select.getCheckoutInfo1(setroomtype);
//                        System.out.println(che.getGuest_name());
//                        Checkout checkout=new Checkout(che);
//                        checkout.setVisible(true);
//                    } else {
//                        JOptionPane.showMessageDialog(null, "您选择的房间暂未被使用！");
//                    }
//                }
            }
        });
        ImageIcon icon4 = new ImageIcon(this.getClass().getResource("img/ToolBar/m05.gif"));
        icon4.setImage(icon4.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton kfyd = new JButton("客房预订", icon4);
        kfyd.setBounds(325, 10, 90, 100);
        kfyd.setContentAreaFilled(false);
        kfyd.setFocusPainted(false);
        kfyd.setHorizontalTextPosition(SwingConstants.CENTER);
        kfyd.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(kfyd);
        kfyd.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                Custom_type custom_type = new Custom_type();
                custom_type.setVisible(true);
            }
        });
        ImageIcon icon5 = new ImageIcon(this.getClass().getResource("img/ToolBar/m06.gif"));
        icon5.setImage(icon5.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton yycx = new JButton("营业查询", icon5);
        yycx.setBounds(430, 10, 90, 100);
        yycx.setContentAreaFilled(false);
        yycx.setFocusPainted(false);
        yycx.setHorizontalTextPosition(SwingConstants.CENTER);
        yycx.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(yycx);
        yycx.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                YYCX yycx1 = new YYCX();
            }
        });
        ImageIcon icon6 = new ImageIcon(this.getClass().getResource("img/ToolBar/m07.gif"));
        icon6.setImage(icon6.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton khgl = new JButton("客户管理", icon6);
        khgl.setBounds(535, 10, 90, 100);
        khgl.setContentAreaFilled(false);
        khgl.setFocusPainted(false);
        khgl.setHorizontalTextPosition(SwingConstants.CENTER);
        khgl.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(khgl);
        khgl.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                CustManage custManage =new CustManage();

            }
        });
        ImageIcon icon7 = new ImageIcon(this.getClass().getResource("img/ToolBar/m08.gif"));
        icon7.setImage(icon7.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton wlsz = new JButton("网络设置", icon7);
        wlsz.setBounds(640, 10, 90, 100);
        wlsz.setContentAreaFilled(false);
        wlsz.setFocusPainted(false);
        wlsz.setHorizontalTextPosition(SwingConstants.CENTER);
        wlsz.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(wlsz);
        wlsz.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
//                WL wl = new WL();
//                wl.setVisible(true);
            }
        });
        ImageIcon icon8 = new ImageIcon(this.getClass().getResource("img/ToolBar/m09.gif"));
        icon8.setImage(icon8.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton xtsz = new JButton("系统设置", icon8);
        xtsz.setBounds(745, 10, 90, 100);
        xtsz.setContentAreaFilled(false);
        xtsz.setFocusPainted(false);
        xtsz.setHorizontalTextPosition(SwingConstants.CENTER);
        xtsz.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(xtsz);
        xtsz.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                if (admin.getAdminname() == null || admin.getAdminname().equals("超级管理员") == false) {
                    JOptionPane.showMessageDialog(null, "您不是管理员无法进入系统设置");
                    return;
                }
                Operator operator = new Operator(admin);
                operator.setVisible(true);
            }
        });
        ImageIcon icon9 = new ImageIcon(this.getClass().getResource("img/ToolBar/m03.gif"));
        icon9.setImage(icon9.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton gywm = new JButton("关于我们", icon9);
        gywm.setBounds(850, 10, 90, 100);
        gywm.setContentAreaFilled(false);
        gywm.setFocusPainted(false);
        gywm.setHorizontalTextPosition(SwingConstants.CENTER);
        gywm.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(gywm);
        gywm.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
//                AboutUs aboutUs = new AboutUs();
//                aboutUs.setVisible(true);
            }
        });
        ImageIcon icon10 = new ImageIcon(this.getClass().getResource("img/ToolBar/m10.gif"));
        icon10.setImage(icon10.getImage().getScaledInstance(66, 66, Image.SCALE_DEFAULT));
        JButton tcxt = new JButton("退出系统", icon10);
        tcxt.setBounds(955, 10, 90, 100);
        tcxt.setContentAreaFilled(false);
        tcxt.setFocusPainted(false);
        tcxt.setHorizontalTextPosition(SwingConstants.CENTER);
        tcxt.setVerticalTextPosition(SwingConstants.BOTTOM);
        getContentPane().add(tcxt);
        tcxt.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                int result = JOptionPane.showConfirmDialog(null, "您现在要关闭系统吗?", "退出提示", 0, 1);
                if (result == JOptionPane.OK_OPTION) {
                    //     int i = updata.addData("UPDATE login_status SET state='未登录' WHERE s_id=1;");
                    JOptionPane.showMessageDialog(null, "已退出系统，欢迎下次使用！");
                    System.exit(0);
                }
            }
        });
        JLabel time = new JLabel();
        time.setForeground(Color.decode("#7784BD"));
        time.setBounds(10, 120, 170, 50);
        time.setFont(new Font("微软雅黑", Font.BOLD, 15));
        getContentPane().add(time);
        this.setTimer(time);

        Font font1 = new Font("微软雅黑", Font.BOLD, 17);
        // Font font2 = new Font("微软雅黑", Font.BOLD, 15);

        fjgg = new JLabel("标准单人间 ：");
        fjgg.setFont(font1);//设置字体
        fjgg.setForeground(Color.red);//设置字体颜色
        fjgg.setBounds(20, 165, 118, 30);
        getContentPane().add(fjgg);
        int i = 1;
        bkxm = new JLabel("宾客姓名 ：");
        bkxm.setBounds(20, 200, 200, 20);
        getContentPane().add(bkxm);
        ysdj = new JLabel("预设单价 ：");
        ysdj.setBounds(20, 225, 200, 20);
        getContentPane().add(ysdj);
        fjdh = new JLabel("房间电话 ：");
        fjdh.setBounds(20, 250, 200, 20);
        getContentPane().add(fjdh);
        fjlx = new JLabel("房间类型 ：");
        fjlx.setBounds(20, 275, 200, 20);
        getContentPane().add(fjlx);
        jdsj = new JLabel("进店时间 ：");
        jdsj.setBounds(20, 300, 220, 20);
        jdsj.setFont(new Font("微软雅黑", 0, 12));
        getContentPane().add(jdsj);

        yjyj = new JLabel("已交押金 ：");
        yjyj.setBounds(20, 325, 220, 20);
        getContentPane().add(yjyj);


        JLabel fjzzt = new JLabel("房间总状态 ：");
        fjzzt.setFont(font1);//设置字体
        fjzzt.setForeground(Color.red);//设置字体颜色
        fjzzt.setBounds(20, 385, 130, 50);
        getContentPane().add(fjzzt);
        JLabel fjzs = new JLabel("房间总数 ：");
        fjzs.setBounds(20, 430, 130, 30);
        getContentPane().add(fjzs);
        String fjzsSql = "SELECT COUNT(*) FROM room_info a ,r_state_info b  WHERE a.r_state=b.id;";
        JLabel fjzs_t = new JLabel(select.getdate(fjzsSql) + "");
        fjzs_t.setForeground(Color.BLUE);
        fjzs_t.setFont(new Font("宋体", Font.BOLD, 18));
        fjzs_t.setBounds(97, 436, 72, 18);
        getContentPane().add(fjzs_t);
        /**
         * 查看当前预定的信息
         */
        JLabel dqzy = new JLabel("当前占用 ：");
        dqzy.setBounds(20, 448, 130, 40);
        getContentPane().add(dqzy);
        String dqzySql = "SELECT COUNT(*) FROM room_info a ,r_state_info b  WHERE a.r_state=b.id AND b.r_state='不可用';";
        JLabel dqzy_t = new JLabel(select.getdate(dqzySql) + "");
        dqzy_t.setFont(new Font("宋体", Font.BOLD, 18));
        dqzy_t.setForeground(Color.BLUE);
        dqzy_t.setBounds(97, 459, 72, 18);
        getContentPane().add(dqzy_t);
        /**
         * 查看当前放假不可用的房间数
         */
        JLabel dqkg = new JLabel("当前可供 ：");
        dqkg.setBounds(20, 467, 130, 50);
        getContentPane().add(dqkg);
        String dqkgSql = "SELECT COUNT(*) FROM room_info a ,r_state_info b  WHERE a.r_state=b.id AND b.r_state='可用';";
        JLabel dqkg_t = new JLabel(select.getdate(dqkgSql) + "");
        dqkg_t.setFont(new Font("宋体", Font.BOLD, 18));
        dqkg_t.setForeground(Color.BLUE);
        dqkg_t.setBounds(97, 483, 72, 18);
        getContentPane().add(dqkg_t);

        JLabel dqyd = new JLabel("当前预订 ：");
        dqyd.setBounds(20, 487, 130, 60);
        getContentPane().add(dqyd);
        String dqydSql = "SELECT COUNT(*) FROM  room_info a ,r_state_info b WHERE a.r_state=b.id  AND b.r_state='被预订';";
        JLabel dqyd_t = new JLabel(select.getdate(dqydSql) + "");
        dqyd_t.setFont(new Font("宋体", Font.BOLD, 18));
        dqyd_t.setForeground(Color.BLUE);
        dqyd_t.setBounds(97, 508, 72, 18);
        getContentPane().add(dqyd_t);

        JLabel dqty = new JLabel("当前停用 ：");
        dqty.setBounds(20, 508, 130, 70);
        getContentPane().add(dqty);
        String stopsql = "SELECT COUNT(*) FROM room_info a ,r_state_info b  WHERE a.r_state=b.id AND b.r_state='不可用';";
        JLabel dqty_t = new JLabel(select.getdate(stopsql) + "");
        dqty_t.setFont(new Font("宋体", Font.BOLD, 18));
        dqty_t.setForeground(Color.BLUE);
        dqty_t.setBounds(97, 534, 72, 18);
        getContentPane().add(dqty_t);
        /**=======================================================================**
         *			中间的组件模块
         **=======================================================================**
         */
        roomTypeInfo();
        //按钮


        ImageIcon i3 = new ImageIcon(this.getClass().getResource("img/refurbish.gif"));
        JButton sx = new JButton("   刷      新", i3);
        sx.setBounds(1410, 560, 110, 30);
        sx.setFocusPainted(false);//去掉按钮周围的焦点框
        sx.setContentAreaFilled(false);//设置按钮透明背景
        getContentPane().add(sx);
        sx.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                MainJFrame m = new MainJFrame(admin);
                dispose();
                m.setVisible(true);
                JOptionPane.showMessageDialog(null, "刷新成功！");
            }
        });
        //  按钮设置
        ImageIcon agme_i = new ImageIcon(this.getClass().getResource("img/sunshine.gif"));
        JButton game = new JButton("", agme_i);
        game.setContentAreaFilled(false);//设置按钮透明背景
        game.setFocusPainted(false);//去掉按钮周围的焦点框
        game.setBorderPainted(false);//去边框
        game.setBounds(0, 603, 200, 200);
        game.addActionListener((event) -> {
            JOptionPane.showMessageDialog(null, "想干嘛");
        });
        JSeparator separator = new JSeparator();
        separator.setBounds(0, 623, 219, 10);
        getContentPane().add(separator);
        JSeparator separator_1 = new JSeparator();
        separator_1.setBounds(0, 804, 219, 10);
        getContentPane().add(separator_1);
        getContentPane().add(game);
//        Object[] columnNames = {"入住单号","主房间号","标准单价","客房类型","享受折扣","消费金额","消费时间","记账人"};
//        data = select.getAllCheckoutInfo();//二维数组
        /*

        最近消费记录
         */

        ;
        setStatementDate();
        StatementTable = new JTable(StatementModel);
        StatementTable.getColumnModel().getColumn(0).setPreferredWidth(5);//设置第一列的列宽
        DefaultTableCellRenderer tcr = new DefaultTableCellRenderer();//单元格渲染器
        tcr.setHorizontalAlignment(JLabel.CENTER);//居中显示
        StatementTable.setDefaultRenderer(Object.class, tcr);//设置渲染器
        StatementTable.setFont(new Font("微软雅黑", 0, 15));

        StatementTable.getTableHeader().setFont(new Font(null, Font.BOLD, 14));  // 设置表头名称字体样式
//		StatementTable.getTableHeader().setForeground(Color.RED);                // 设置表头名称字体颜色
        StatementTable.getTableHeader().setResizingAllowed(false);               // 设置不允许手动改变列宽
        StatementTable.getTableHeader().setReorderingAllowed(false);
        JScrollPane jsp = new JScrollPane(StatementTable, v, h);//创建滚动容器
        jsp.setBackground(Color.decode("#E7D7B7"));//设置背景颜色
        jsp.setBounds(220, 603, 1335, 204);
        getContentPane().add(jsp);

        JLabel dqsj = new JLabel("当前时间 ：");
        dqsj.setForeground(Color.decode("#7784BD"));
        dqsj.setBounds(1110, 25, 200, 50);
        dqsj.setFont(new Font("微软雅黑", Font.BOLD, 25));
        getContentPane().add(dqsj);
        getContentPane().add(dqsj);

        JLabel time1 = new JLabel();
        time1.setForeground(Color.decode("#7784BD"));
        time1.setBounds(1110, 40, 407, 115);
        time1.setFont(new Font("宋体", Font.CENTER_BASELINE, 20));
        getContentPane().add(time1);
        this.setTimer(time1);

        Label_1 = new JLabel();//"宾客姓名"
        Label_1.setForeground(Color.BLUE);
        Label_1.setFont(new Font("宋体", Font.BOLD, 15));
        Label_1.setBounds(90, 201, 130, 18);
        getContentPane().add(Label_1);
        Label_2 = new JLabel();//"预设单价"
        Label_2.setForeground(Color.BLUE);
        Label_2.setFont(new Font("宋体", Font.BOLD, 15));
        Label_2.setBounds(90, 226, 130, 18);
        getContentPane().add(Label_2);
        Label_3 = new JLabel();//"房间电话"
        Label_3.setForeground(Color.BLUE);
        Label_3.setFont(new Font("宋体", Font.BOLD, 15));
        Label_3.setBounds(90, 251, 130, 18);
        getContentPane().add(Label_3);
        Label_4 = new JLabel();//"所在区域"
        Label_4.setForeground(Color.BLUE);
        Label_4.setFont(new Font("宋体", Font.BOLD, 15));
        Label_4.setBounds(90, 276, 130, 18);
        getContentPane().add(Label_4);
        Label_5 = new JLabel();//"进店时间"
        Label_5.setForeground(Color.BLUE);
        Label_5.setFont(new Font("宋体", Font.BOLD, 15));
        Label_5.setBounds(90, 301, 130, 18);
        getContentPane().add(Label_5);
        Label_6 = new JLabel();//"已用时间"
        Label_6.setForeground(Color.BLUE);
        Label_6.setFont(new Font("宋体", Font.BOLD, 15));
        Label_6.setBounds(90, 326, 130, 18);
        getContentPane().add(Label_6);
        Label_7 = new JLabel();//"已交押金"
        Label_7.setForeground(Color.BLUE);
        Label_7.setFont(new Font("宋体", Font.BOLD, 15));
        Label_7.setBounds(90, 351, 130, 18);
        getContentPane().add(Label_7);
        Label_8 = new JLabel();//"应收金额"
        Label_8.setForeground(Color.BLUE);
        Label_8.setFont(new Font("宋体", Font.BOLD, 15));
        Label_8.setBounds(90, 376, 130, 18);
        getContentPane().add(Label_8);
    }

    /**
     * 插入最近消费记录的方法
     *
     * @param
     */

    private void setStatementDate() {
        Vector<String> header = new Vector<>();
        header.add("订单编号");
        header.add("房间号码");
        header.add("房价单价");
        header.add("房价类型");
        header.add("消费金额");
        header.add("消费时间");
        header.add("记账人");

        Vector<Vector<Object>> body = new Vector<Vector<Object>>();
        for (Statement s : select.queryStatement()) {
            Vector<Object> v = new Vector<>();
            v.add(s.getId());
            v.add(s.getRoom_id());
            v.add(s.getR_price());
            v.add(s.getRoom_type());
            v.add(s.getB_money());
            v.add(s.getB_time());
            v.add(s.getB_admins());
            body.add(v);
            if (this.StatementModel == null) {
                StatementModel = new DefaultTableModel(body, header);
            }
            this.StatementModel.setDataVector(body, header);
        }
    }

    // 设置Timer 1000ms实现一次动作 实际是一个线程
    private void setTimer(JLabel time) {
        /**
         * 每次间隔100
         */
        final JLabel varTime = time;
        Timer timeAction = new Timer(100, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                long timemillis = System.currentTimeMillis();
                // 转换日期显示格式
                SimpleDateFormat df = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
                varTime.setText(df.format(new Date(timemillis)));
            }
        });
        timeAction.start();
    }

    //界面中间房间状态的方法
    public void roomTypeInfo() {


        tabbedPane = new JTabbedPane();
        tabbedPane.setBounds(220, 130, 1335, 420);
        getContentPane().add(tabbedPane);
        tabbedPane.setBackground(Color.decode("#DBC9ED"));
        ImageIcon ic = null;

        java.util.List<String> rommType = select.getRoomlx();
        for (String s : rommType) {
            JPanel p1 = new JPanel();  //创建面板组件容器

            p1.setLayout(new FlowLayout(FlowLayout.LEFT, 50, 50));//流式布局间距50
            ArrayList<RoomInfo> list_p1 = select.getMainInfoRoom(s);//得到房间号和房间状态存入List集合

            for (int j = 0; j < list_p1.size(); j++) {
                //可用的房间状态
                if (list_p1.get(j).getR_states() == 1) {
                    ic = new ImageIcon(this.getClass().getResource("img/room/prov.gif"));
                    //被预订的房间状态
                } else if (list_p1.get(j).getR_states() == 3) {
                    ic = new ImageIcon(this.getClass().getResource("img/room/pree.gif"));
                    //维护中的房间状态
                } else if (list_p1.get(j).getR_states() == 2) {
                    ic = new ImageIcon(this.getClass().getResource("img/room/stop.gif"));

                } else if (list_p1.get(j).getR_states() == 4) {
                    ic = new ImageIcon(this.getClass().getResource("img/room/rese.gif"));

                } else {//使用中的房间状态
                    ic = new ImageIcon(this.getClass().getResource("img/room/clean.gif"));
                }
                JButton btnNewButton = new JButton("" + list_p1.get(j).getR_rommber(), ic);
                btnNewButton.setHorizontalTextPosition(SwingConstants.CENTER);
                btnNewButton.setVerticalTextPosition(SwingConstants.BOTTOM);
                btnNewButton.setContentAreaFilled(false);//设置按钮透明背景
                btnNewButton.setFocusPainted(false);//边框
                btnNewButton.setBorderPainted(false);//去边框
                //按钮监听事件
                btnNewButton.addActionListener(e-> upDataClietn(btnNewButton.getText()));

                btnNewButton.addMouseListener(new MouseAdapter() {
                    @Override
                    public void mouseClicked(MouseEvent e) {

                        if (e.getClickCount() == 2) {

                            String text = bkxm.getText();
                            String[] split = text.split(":");


                            new CheckOutDemo(select.findCheckOut(btnNewButton.getText(),split[1]),admin.getUsername());
                        } else {
                            System.out.println("单击");
                            upDataClietn(btnNewButton.getText());
                        }


                    }
                });

                btnNewButton.setPreferredSize(new Dimension(120, 100));
                p1.add(btnNewButton);
            }
            //** 查找该操作员的方法*/

            tabbedPane.addTab(s, p1);//将p1面板添加进总面板控件
            JLabel adminuser = new JLabel("当前操作员 : " + admin.getAdminname());
            adminuser.setFont(new Font("宋体", Font.BOLD, 16));
            adminuser.setForeground(Color.RED);//可以直接设置文字颜色
            adminuser.setBounds(1150, 805, 400, 25);
            getContentPane().add(adminuser);

        }


    }


    /**
     * 根据房间的id 查找到住的人 然后把用户的信息渲染到主界面里面
     * 根据房间id查房间状态 如果 是1 就直接返回 不是就继续
     */
    private void upDataClietn(String RoomID) {
        if (select.findRoomType(RoomID)) {
            JOptionPane.showMessageDialog(null, "此房间为空闲状态没有信息");
            return;
        }
        ClientPlus clientPlus = select.querryRoomIdByClient(RoomID);

        if (clientPlus == null) {
            System.out.println("此房间没有用户在住");
            return;
        }
        this.bkxm.setText("宾客姓名 :" + clientPlus.getName());
        this.ysdj.setText("房间单价 :" + clientPlus.getPrice());
        this.fjdh.setText("房间电话 :" + clientPlus.getPhone());
        this.fjlx.setText("房间类型 :" + clientPlus.getRoom_type());
        this.jdsj.setText("进店时间 :" + clientPlus.getData());
        this.yjyj.setText("已交押金 :" + clientPlus.getYj());


    }

    public static void main(String[] args) {
        Admin admin = new Admin();
        admin.setPwd("123");
        admin.setUsername("超级管理员");
        new MainJFrame(admin).setVisible(true);
    }


}

